package edu.gatech.cs2340.tigershroud;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

/**
 * The TodoListActivity is the main page that the user with interact with
 * to view tasks.
 * @author []
 * @version 9.0x, Build April 3, 2012.
 */

public class TaskViewActivity extends Activity
{
	private TodoDataSource ds;
	private Button edit, back;
	private TextView uname, tname, des, date, cat, stat, addr, time, city, state, zip, prior;
	private Task displayTask;
	
	/**
	 * The onCreate method is a default android method that is called when the
	 * activity is first started. This onCreate method assigns passed objects to variables, 
	 * opens the database, determines the layout of
	 * the activity, and sets listeners for items within the activity.
	 * @param saveInstanceState the Bundle name value pair that represents the state of the object
	 *
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.taskview);
       
        ds = new TodoDataSource(this);
        ds.open();
        
        edit = (Button) findViewById(R.id.editButton);
        back = (Button) findViewById(R.id.backButton);
        uname = (TextView) findViewById(R.id.tvowner);
        tname = (TextView) findViewById(R.id.nameout);
        des = (TextView) findViewById(R.id.descout);
        date = (TextView) findViewById(R.id.dateout);
        cat = (TextView) findViewById(R.id.catout);
        stat = (TextView) findViewById(R.id.compout);
        addr = (TextView) findViewById(R.id.addrout);
        time = (TextView) findViewById(R.id.tvtime);
        city = (TextView) findViewById(R.id.tvcity);
        state = (TextView) findViewById(R.id.tvstate);
        zip = (TextView) findViewById(R.id.tvzip);
        prior = (TextView) findViewById(R.id.tvprior);
        
        Intent i = getIntent();
        displayTask = (Task)i.getSerializableExtra("clickedTask");
        
        uname.setText(displayTask.getUserName());
        tname.setText(displayTask.getTaskName());
        des.setText(displayTask.getDescription());
        date.setText(displayTask.getDate());
        time.setText(displayTask.getTime());
        cat.setText(displayTask.getCategory());
        addr.setText(displayTask.getAddress());
        city.setText(displayTask.getCity());
        state.setText(displayTask.getState());
        zip.setText(displayTask.getZipCode());
        prior.setText(displayTask.getPriority());

        if(displayTask.getStatus().equals("1"))
        {
        	stat.setText("Complete");
        	Log.d("STAT", "complete");
        }
        else
        {
        	stat.setText("Incomplete");
        	Log.d("STAT", "incomplete");
        }
        
        edit.setOnClickListener(new View.OnClickListener() 
        {
    	   public void onClick(View v) 
    	   {
    		   ds.close();
    		   Intent intent = new Intent(getApplicationContext(), TaskActivity.class);
    		   intent.putExtra("date", "");
    		   intent.putExtra("time", "");
    		   intent.putExtra("dnum", "");
    		   intent.putExtra("task", displayTask);

    		   startActivity(intent);
       		   finish();
    	   }
        });
       
        back.setOnClickListener(new View.OnClickListener() 
        {
        	public void onClick(View v) 
        	{
        		ds.close();
        		finish();
        	}
        });
    }
}
